package com.itheima.service.impl;

import com.itheima.mapper.BrandMapper;
import com.itheima.pojo.Brand;
import com.itheima.pojo.Page;
import com.itheima.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 刘全
 * @date 2021/9/8
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    private BrandMapper bm;


    /**
     * 查询所有
     *
     * @return
     */
    @Override
    public List<Brand> selectAll() {
        List<Brand> brands = bm.selectAll();
        return brands;
    }

    /**
     * 添加
     *
     * @param brand
     */
    @Override
    public int add(Brand brand) {
        return bm.add(brand);
    }

    /**
     * 删除数据
     *
     * @param id
     */
    @Override
    public int deleteById(int id) {
        return bm.deleteById(id);
    }

    /**
     * 修改数据
     *
     * @param brand
     */
    @Override
    public int update(Brand brand) {
        return bm.update(brand);
    }

    /**
     * 批量删除
     *
     * @return
     */
    @Override
    public int deleteByIds(int[] ids) {
        return bm.deleteByIds(ids);
    }

    /**
     * 分页查询
     * @param index
     * @param pageSize
     * @return
     */
    @Override
    public Page<Brand> selectPage(int index, int pageSize) {
        List<Brand> brands = bm.selectPage(index, pageSize);
        int count = bm.selectPagecount();
        Page p = new Page();
        p.setList(brands);
        p.setPageCount(count);
        return p;
    }

    /**
     * 条件查询
     *
     * @param page
     * @param pageSize
     * @param brand
     * @return
     */
    @Override
    public Page<Brand> selectByPageAndCondition(int page, int pageSize, Brand brand) {
        int index = (page - 1) * pageSize;
        List<Brand> brands = bm.selectByPageAndCondition(index, pageSize, brand);
        int count = bm.selectPagecount2(brand);
        Page p = new Page();
        p.setList(brands);
        p.setPageCount(count);
        return p;
    }
}
